package cn.ante.ymcc.mq.consumer;

import cn.ante.ymcc.dto.PayAliNotifyDto;
import cn.ante.ymcc.service.ICourseOrderService;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
* @Description: 支付服务消费订单服务  消费只能成功消费一次，
 * 如果消息被别人消费了，会显示消息已签收，不会再推送给另一个消费者，怎么标记已签收：只要方法不报错就自动签收了
* @Author: Nai
* @Version: 1.0
* @Date:  2022/8/20 22:30
*/
@Component
@RocketMQMessageListener(topic = "cancel-order-topic",
        consumerGroup = "paytimeout-order-consumer",
        messageModel = MessageModel.BROADCASTING,
        selectorExpression = "paytimeout-tags"
)
public class OrderCancelByPayTimeOutConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private ICourseOrderService courseOrderService;

    /**
     * 消费者只能成功消费一次
     *  消息签收  怎么标记为已签收？？
     *   答：你不报错就是已签收
     * 这个方法只要不报错，就是自动签收
     *
     * @param
     */
    @Override
    public void onMessage(MessageExt message) {
        String courseOrderNo = new String(message.getBody(), StandardCharsets.UTF_8);
        if (StringUtils.isEmpty(courseOrderNo)){
            return;
        }
        courseOrderService.cancelOrderByPayTimeOut(courseOrderNo);

    }
}
